package com.hy.hongying.util;

import java.lang.reflect.Field;

public class BeanCopy {
    public static <T>T getTrance(Class<T> clz,Object ojb){
        T t = null;
        try {
            t = clz.newInstance();
            Field[] Fields = ojb.getClass().getDeclaredFields();

            for(Field f:Fields){
                f.setAccessible(true);
                Field[] fields = clz.getClass().getDeclaredFields();


                for(Field s : fields){
                    if(!s.getName().equals(f.getName())){
                        continue;
                    }
                }


                try {
                    Field df = clz.getDeclaredField(f.getName());
                    df.setAccessible(true);
                    df.set(t,f.get(ojb));
                } catch (NoSuchFieldException e) {
                    e.printStackTrace();
                }
            }
            return t;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    } 
}
